export const transformRoutes = (routes, parentPath = '') => {
    return routes
        .filter(route => {
            // 只过滤明显无效的菜单（保留M目录和C菜单）
            const isValid = route.menuType === 'M' || route.menuType === 'C'
            if (!isValid) {
            }
            return isValid
        })
        .map(route => {
            // 拼接完整路径
            const fullPath = parentPath ? `${parentPath}/${route.path}` : route.path
            const routePath = fullPath.startsWith('/') ? fullPath : `/${fullPath}`

            // 构建路由配置
            const transformedRoute = {
                path: routePath,
                name: `Menu-${route.menuId || route.path}`, // 确保name唯一
                meta: {
                    title: route.menuName,
                    icon: route.icon || 'Menu', // 默认为菜单图标
                    visible: route.visible ?? '0', // 默认为显示
                    order: route.order ?? 10 // 排序值（大于首页的0）
                },
                // 目录用空布局，菜单用实际组件
                component: route.menuType === 'M'
                    ? () => import('@/views/layout/EmptyLayout.vue')
                    : () => import(`@/views/${route.component}`)
            }

            // 处理子菜单（递归）
            if (route.children && route.children.length > 0) {
                transformedRoute.children = transformRoutes(route.children, fullPath)
                // console.log(`菜单${route.menuName}的子菜单:`,
                //     transformedRoute.children.map(c => c.path))
            }

            return transformedRoute
        })
}
